{extend name="Public/base" /}
{block name="main"}
    <fieldset class="layui-elem-field">
        <legend>新增用户 - 目录列表</legend>
        <div class="layui-field-box">
            <form style="width:50%;" class="layui-form" action="">
                <div class="layui-form-item" style="float:left;margin-left: -109px;">
                    <div class="layui-input-block" >
                        <input style="width:200px;float: left;" type="text" name="password" value="" placeholder="设置统一密码" class="layui-input" />
                        <button id='addAll' class="layui-btn" lay-submit lay-filter="admin-form">一键设置全部用户</button>
                        <!-- <input type="submit" class="layui-btn" value="一键设置全部用户" /> -->
                    </div>
                </div>
            </form>
<script>
layui.use('form', function(){
    var form = layui.form();
    form.on('submit(admin-form)', function(data){
        $('#addAll').css('background-color',"grey");
        $('#addAll').css('cursor',"default");
        $('#addAll').attr('disabled',"true");
        $.ajax({
            type: "POST",
            url: '{:U("addAll")}',
            data: data.field,
            success: function(msg){
                // console.log(msg);
                if( msg.code == 1 ){
                    location.reload();
                    // parent.location.reload();
                }else{
                    $(".layui-table tbody").html('');
                    $.each(msg, function(i,n){
                        var spanT = "<span class='layui-btn layui-btn-disabled'>设定用户名</span>"
                        var template="<tr><td>"+i+"</td><td>"+n['name']+"<span style='color:red;'>"+n['errMsg']+"</span></td><td>"+spanT+"</td></tr>";
                        $(".layui-table tbody").append(template);
                    })

                }
            }
        });
        return false;
    });
});
</script>
            <!-- <span class="layui-btn layui-btn-normal"><a href='{:U("addAll")}'>一键设置全部用户</a></span> -->
            <form style="width:50%;float:right;" class="layui-form" method='post' action="{:U('setDir')}">
                <div class="layui-form-item" style="margin-right: 60px;">
                    <div class="layui-input-block" style="float: right;">
                        <input style="width:200px;float: left;" type="text" name="dir" value="{$dir}" placeholder="" class="layui-input" />
                        {if condition="$count"}
                            <input type="submit" class="layui-btn layui-btn-danger" value="目录数量接近上限，为了保证您的数据安全，请及时更换根目录" />
                        {else}
                            <input type="submit" class="layui-btn" value="设置用户根目录" />
                        {/if}
                    </div>
                </div>
            </form>

            <table class="layui-table" lay-even>
                <thead>
                <tr>
                    <th>#</th>
                    <th style="width: 60%">目录名</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="list" id="vo"}
                    <tr>
                        <td>{$i}</td>
                        <td>{$vo['name']}
                            {if condition="$vo['msg']"}
                                <span style='color:red;'>：添加用户失败，此用户已存在，请手动设定。===></span>
                            {elseif condition="$vo['err']"}
                                <span style='color:red;'>：目录名特殊符号或使用全角，请修改</span>
                            {/if}
                            {if condition="$vo['errMsg']"}
                                <span style='color:red;'>：{$vo['errMsg']}，请修改</span>
                            {/if}
                        </td>
                        <td>
                            {if condition="$vo['err']"}
                                <span class="layui-btn layui-btn-disabled">设定用户名</span>
                            {else}
                                <span data-url="{:url('addOne',['user_name'=>$vo[bname]])}" class="layui-btn customer-edit layui-btn-normal">设定用户名</span>
                            {/if}
                        </td>
                    </tr>
                {/volist}
                </tbody>
            </table>
        </div>
    </fieldset>
{/block}
{block name="myScript"}
    <script>
        layui.use(['layer'], function() {
            $('.api-add').on('click', function () {
                layer.open({
                    type: 2,
                    area: ['60%', '60%'],
                    maxmin: true,
                    content: '{:U("add")}'
                });
            });
            $('.customer-edit').on('click', function () {
                layer.open({
                    type: 2,
                    area: ['60%', '60%'],
                    maxmin: true,
                    content: $(this).attr('data-url')
                });
            });
            $('.edit').on('click', function () {
                var ownObj = $(this);
                //location.href = 'ownObj.attr('data-url')';
                
                location.href=ownObj.attr('data-url');
            });
            $('.confirm').on('click', function () {
                var ownObj = $(this);
                layer.confirm(ownObj.attr('data-info'), {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    $.ajax({
                        type: "POST",
                        url: ownObj.attr('data-url'),
                        data: {id:ownObj.attr('data-id')},
                        success: function(msg){
                            if( msg.code == 1 ){
                                location.reload();
                            }else{
                                layer.msg(msg.msg, {
                                    icon: 5,
                                    shade: [0.6, '#393D49'],
                                    time:1500
                                });
                            }
                        }
                    });
                });
            });
        });
    </script>
{/block}